<template>
  <div>
    <div id="box">
      <header>
        <div>
          <img src="/static/img/back.png" alt="" @click="backClick">
          <span>注册</span>
        </div>
        <div>
          <img src="/static/img/客服.png" alt="">
          <img src="/static/img/更多01.png" alt="">
        </div>
      </header>
      <main>
        <div class="cell">
          <label>注册账号：</label>
          <input type="text" placeholder="请输入您要注册的账号" v-model="username" @input="conformAll">
        </div>
        <div class="cell">
          <label>账号密码：</label>
          <input type="password" placeholder="请输入您的密码" v-model="psw" @input="conformAll">
        </div>
        <div class="cell">
          <label>确认密码：</label>
          <input type="password" placeholder="确认密码" v-model="conform" @input="conformAll">
        </div>
        <div id="regist">
          <p>点击注册，表示您同意 <a href="">《服务协议及隐私声明》</a></p>
          <button :disabled="isActive" @click="btnClick">注册</button>
        </div>
      </main>
    </div>
  </div>
</template>

<script>
  export default {
    data:function () {
      return {
        isActive:true,
        username:"",
        psw:"",
        conform:""
      }
    },
    methods:{
      conformAll:function () {
        let con = this.username&&this.psw&&(this.psw == this.conform);
        if (con) {
          this.isActive = false
        } else {
          this.isActive = true
        }
      },
      btnClick:function () {
        let param = {
          username:this.username,
          psw:this.psw
        };
        this.http.post('/api/users/regist',param)
          .then(res=>{
            this.$layer.msg(res.data.msg);
            if(!res.data.err){
              location.hash = '/login'
            }
          })
      },
      backClick:function () {
        history.back()
      },
    }
  }
</script>

<style scoped>
  #box{
    height: 100vh;
    background-color: rgb(245,245,245);
  }
  header {
    background-color: rgb(0, 71, 156);
    height: 50px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 12px;
  }
  header div{
    display: flex;
    align-items: center;
  }
  header div span{
    color: white;
    margin-left: 12px;
    position: relative;
    top: -2px;
  }
  main{
    margin-top: 24px;
  }
  .cell{
    background-color: white;
    padding: 6px 0;
    padding-left: 30px;
  }
  input {
    border: none;
    border-bottom: solid 1px #dddddd;
    width: 70vw;
    margin-bottom: 8px;
    height: 30px;
    padding: 4px;
  }
  #regist{
    padding: 6px 30px;
  }
  button{
    width: 100%;
    height: 44px;
    background-color: rgb(255,60,60);
    border: none;
    border-radius: 6px;
    margin-top: 6px;
    color: white;
    font-size: 17px;
  }
  label{
    font-size: 14px;
  }
  p a{
    color: rgb(0, 71, 156);
    text-decoration: none;
  }
  p{
    font-size: 15px;
  }
  button:disabled{
    background-color: #c6c6c6;
  }
</style>
